package com.inspinia.upms.common.util;


import com.inspinia.base.cache.CacheUtil;
import com.inspinia.base.common.model.UserCacheKeys;

import java.util.List;

/**
 * 清除缓存的工具类
 * Created by veblen on 16/9/21.
 */
public class CacheClearUpUtil {
    /**
     * 清除所有用户已有权限的缓存
     */
    public static void cleanUserResourceCache() {
        CacheUtil.deleteByReg(UserCacheKeys.getUserResourceKey(null) + "*");
        CacheUtil.deleteByReg(UserCacheKeys.getUserMenuKey(null) + "*");
    }

    /**
     * 清除单个用户已有权限的缓存
     */
    public static void cleanUserResourceCache(Long userId) {
        CacheUtil.delete(UserCacheKeys.getUserResourceKey(userId));
        CacheUtil.delete(UserCacheKeys.getUserMenuKey(userId));
    }


    /**
     * 清除用户已有权限的缓存
     */
    public static void cleanUserResourceCache(List<Long> userIds) {
        userIds.forEach(CacheClearUpUtil::cleanUserResourceCache);
    }

}
